const publicFun = require('/utils/public.js')
const apiUrl = 'https://nginx.ipe.org.cn/app/app_v3.asmx'; //接口域名
const ossUrl = 'https://oaossupv.ipe.org.cn:7778/app'; //证书域名

export const getMiyao = (data) => {return requestPostApi(apiUrl+'/GetSecondCount', data)}; //密钥
export const getAuthCode = (data) => {return requestPostApi(apiUrl+ '/GetZhiFubaoCodeForClimate', data)} // 获取支付宝user_id
export const getAuthCodeLogin = (data) => {return requestPostApi(apiUrl+'/GetZhiFubaoUserInfo_Login_XCX', data)}; //获取支付宝user_id并授权登录
export const getriskContent = (data) => {return requestPostApi(apiUrl+'/GetZhiFubaoRiskContent', data)}; //文本风险识别

export const getClimateActionTab = (data) => {return requestPostApi(apiUrl + '/ClimateAction', data)} //获取气候行动tab
export const getClimateActionDetail = (data) => {return requestPostApi(apiUrl + '/ClimateActionDetail_V1', data)} //获取气候行动上传详情页
export const getAqiContent = (data) => {return requestPostApi(apiUrl+'/GetAQIInfo_NameAndLL', data)}; //获取默认空气内容
export const setClimateActionSubmit = (data) => {return requestPostApi(apiUrl + '/ClimateActionSubmit', data)} //提交气候行动


export const ssCurrentDetail = (data) => {return requestPostApi(apiUrl+'/ShareContent_V1_Base64', data)}; //ss详情页（只有当前的一条）
export const ssCurrentDetailType = (data) => {return requestPostApi(apiUrl+'/GetShareWallTypeByWallId_V3_1', data)}; //ss详情页（只有当前的一条） type
export const ssSharePictureList = (data) => {return requestPostApi(apiUrl+'/SharePictureList', data)}; //ss详情页多图
export const ssCommentList = (data) => {return requestPostApi(apiUrl+'/ShareCommentList', data)}; //ss详情全部评论

export const like = (data) => {return requestPostApi(apiUrl+'/ShareWall_Praise', data)}; //点赞
export const unlike = (data) => {return requestPostApi(apiUrl+'/ShareWall_Praise_Remove', data)}; //取消点赞
export const ssDelete = (data) => {return requestPostApi(apiUrl+'/DelShare_V1', data)}; //删除晒晒
export const commentSub = (data) => {return requestPostApi(apiUrl+'/ShareWall_AddComment_V2', data)}; //发评论
export const commentAllList = (data) => {return requestPostApi(apiUrl+'/ShareCommentList_V1', data)}; //全部评论列表

export const getClimateActionList = (data) => {return requestPostApi(apiUrl + '/ShareList_V4_3_Carbon', data)} //获取气候行动瀑布流列表
export const getClimateActionRank = (data) => {return requestPostApi(apiUrl + '/ClimateActionUserPaiHangBang', data)} //获取气候行动排行榜列表

export const getClimateActionTJ = (data) => {return requestPostApi(apiUrl + '/ClimateActionUserTongJi', data)} //获取打卡总减碳数据
export const getClimateActionType = (data) => {return requestPostApi(apiUrl + '/ClimateActionUserTypeList', data)} //获取我的打卡列表
export const getClimateActionUserHistory = (data) => {return requestPostApi(apiUrl + '/ClimateActionUserHistory', data)} //获取我的打卡列表审核状态
export const getClimateActionUserDay = (data) => {return requestPostApi(apiUrl + '/ClimateActionUserIsFirstDay', data)} //获取本用户是否首日提交
export const getClimateActionWithType = (data) => {return requestPostApi(apiUrl + '/ClimateActionUserTypeList_WithType', data)} //气候行动用户类型列表带一级大类
export const getClimateActionWithoutType = (data) => {return requestPostApi(apiUrl + '/ClimateActionUserTypeList_WithoutType', data)} //气候行动用户类型列表不带一级大类

export const getJianSuQuestions = (data) => {return requestPostApi(apiUrl + '/JianSu_Questions', data)};  //获取减塑问卷
export const setSubmitJianSu = (data) => {return requestPostApi(apiUrl + '/JianSu_GuanCha_SubMit_V1', data)};  //提交减塑信息
export const getJianSuTimes = (data) => {return requestPostApi(apiUrl + '/JianSu_GetTimes', data)}; //获取地址提交次数
export const getJianSuGuanChaList = (data) => {return requestPostApi(apiUrl + '/JianSu_GuanChaList', data)};  //减塑列表
export const getJianSuDetail = (data) => {return requestPostApi(apiUrl + '/JianSu_Detail', data)};  //减塑详情
export const setJianSuDel = (data) => {return requestPostApi(apiUrl + '/JianSu_Del', data)};  //删除减塑信息


export const sendCode = (data) => {return requestPostApi(apiUrl + '/ModifyUser_HeBing_PhoneSendCode_V1', data)} //绑定手机号发送验证码
export const bindMobile = (data) => {return requestPostApi(apiUrl + '/ModifyUser_HeBing_ModifyPhone_V1', data)} //绑定手机号
export const mergeAccount = (data) => {return requestPostApi(apiUrl + '/ModifyUser_HeBing_V2', data)} //合并数据
export const quickLogin = (data) => {return requestPostApi(apiUrl + '/User_RegisterOrLogin_V1', data)} //快捷登录
export const quickLoginCode = (data) => {return requestPostApi(apiUrl + '/User_RegisterOrLogin_SendCode_V1', data)}  //快捷登录手机号验证码

export const userData = (data) => {return requestPostApi(apiUrl+'/User_Center_V2', data)}; //用户信息
export const modifyUserName = (data) => {return requestPostApi(apiUrl+'/ModifyUser_NickName', data)} //修改用户名

export const userFeedBack = (data) => {return requestPostApi(apiUrl + '/UserFeedBack_V3_3', data)}; //用户反馈
export const userFeedBackList = (data) => {return requestPostApi(apiUrl + '/UserFeedBack_Reply', data)}; //用户反馈回复列表

export const userNGOList= (data) => {return requestPostApi(apiUrl + '/NGO_List_V1', data)}; //隶属机构列表及搜索
export const userNGODetail= (data) => {return requestPostApi(apiUrl + '/NGO_Detail', data)}; //隶属机构详情
export const userNGOTeamList= (data) => {return requestPostApi(apiUrl + '/NGO_Team_List', data)}; //隶属机构-社团
export const userNGOModify= (data) => {return requestPostApi(apiUrl + '/ModifyUser_NGO_V2', data)}; // 更改隶属机构

export const getMedalList = (data) => {return requestPostApi(apiUrl + '/UserCenter_ScoreShop_HuanXunZhang_Detail_V1', data)}; // 勋章列表
export const getMedal = (data) => {return requestPostApi(apiUrl + '/DuiHuan_XunZhang_V1', data)}; // 领取勋章

export const getCertificateList = (data) => {return requestPostApi(apiUrl + '/Garbage_ZhengShuHuoDong_V1', data)}; // 证书列表
export const getCertificateDetail = (data) => {return requestPostApi(apiUrl + '/Garbage_ZhengShuHuoDong_Detail', data)}; // 证书申请
export const setGenerateCertificate = (data) => {return requestPostApi(ossUrl+'/GetZhengShu.ashx', data)}; // 证书生成

export const GongYiLog = (data) => {return requestPostApi(apiUrl + '/GY_GongYiLog', data)}; //日志

// request get 请求
const requestGetApi = (url, param) => {
  const app = getApp();
  if(app.globalData.secondCount){
    param.miyao = param.miyao ? param.miyao : app.getMiYao();
  }
  param.devicetype = 'zfb_climate';
  param.Token = param.Token ? param.Token : '';
  return new Promise((resolve, reject) => {
    my.request({
      url: url,
      method: 'GET',
      data: param,
      // dataType: 'json',
      headers: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success (res) {
        resolve(res.data)
      },
      fail (err) {
        publicFun.showToast(err.message);
        reject(err)
      }
    })
  })
}
// request post 请求
const requestPostApi = (url, param) => {
  const app = getApp();
  if(app.globalData.secondCount){
    param.miyao = param.miyao ? param.miyao : app.getMiYao();
  }
  param.devicetype = 'zfb_climate';
  param.Token = param.Token ? param.Token : '';
  return new Promise((resolve, reject) => {
    my.request({
      url: url,
      method: 'POST',
      data: param,
      // dataType: 'json',
      headers: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success (res) {
        resolve(res.data)
      },
      fail (err) {
        publicFun.showToast(err.message);
        reject(err)
      }
    })
  })
}

// module.exports = {
//   requestGetApi,
//   requestPostApi
// }

